/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package BESA.SystemLevel.Directory.greenpages;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 *
 * @author Andrea
 */
 class Group implements Serializable{

 
	private static final long serialVersionUID = -6222897456933490472L;
	private List<String> agIds;
    private String groupId;
    private List<String> descriptors;
    private String societyName;

    public Group(String groupName, String societyName) {
        groupId = groupName;
        this.societyName=societyName;
        descriptors = new ArrayList<String>();
        agIds = new ArrayList<String>();
    }

    public boolean hasDescriptor(String descriptor) {
        for (int i = 0; i < descriptors.size(); i++) {
            if (descriptors.get(i).equals(descriptor)) {
                return true;
            }
        }
        return false;
    }

    public List<String> getAgIds() {
        return agIds;
    }

    public String getGroupName() {
        return groupId;
    }

    public boolean agentIsRegistered(String agId) {
        for (int i = 0; i < agIds.size(); i++) {
            if (agIds.get(i).equals(agId)) {
                return true;
            }
        }
        return false;
    }

    public boolean registerAgent(String agId) {
        if (!agentIsRegistered(agId)) {
            this.agIds.add(agId);
            return true;
        }
        return false;
    }

    public boolean unregisterAgent(String agId) {
        if (agentIsRegistered(agId)) {
            this.agIds.remove(agId);
            return true;
        }else{
            return false;
        }
    }


    public boolean setDescriptor(String descriptor) {
        if (!this.hasDescriptor(descriptor)) {
            this.descriptors.add(descriptor);
            return true;
        }
        return false;
    }

//    public boolean setDescriptors(List<String> descriptors) {
//        boolean result=true;
//        for (int i = 0; i < descriptors.size(); i++) {
//            result&=setDescriptor(descriptors.get(i));
//        }
//        return result; //Alguno de los descriptores no se agrego....
//    }

    @Override
    public int hashCode() {
        return groupId.hashCode();
    }

    public String getSocietyName() {
        return societyName;
    }



}
